var pageii = null;
var grid = null;
$(function() {

	grid = lyGrid({
		pagId : 'paging',
		l_column : [{
			colkey : "Name",
			name : "名称"
		},{
			colkey : "number",
			name : "订单数量"
		},{
			colkey : "client_weight",
			name : "定重"
		}, {
			colkey : "receiving_date",
			name : "接单日期",
			renderData : function(rowindex,data, rowdata, column) {
				if(data==null||data==''){
					return " ";
				}else{
					return new Date(data).format("yyyy-MM-dd hh:mm:ss");
				}
				}
		}, {
			colkey : "po_no",
			name : "采购订单号"
		}, {
			colkey : "client_encode",
			name : "编码"
		}, {
			colkey : "shipping_time",
			name : "出货时间",
			renderData : function(rowindex,data, rowdata, column) {
				if(data==null||data==''){
					return " ";
				}else{
					return new Date(data).format("yyyy-MM-dd hh:mm:ss");
				}
			}
		},{
		    colkey : "job_number",
			name : "作业号"
		},{
			colkey : "price",
			name : "单价"
		},{
			colkey : "sale",
			name : "业务员"
		},{
			colkey : "planner",
			name : "计划员"
		},{
			colkey : "order_state",
			name : "订单状态",
			renderData : function(rowindex,data, rowdata, column) {
				if(data==1){
					return "已接收";
				}else if(data==2){
					return "审核中";
				}else{
					return "未接受";
				}
			}
		},{
			colkey : "finish_time",
			name : "订单完成时间",
			renderData : function(rowindex,data, rowdata, column) {
				if(data!=''&&data!=null){
					return new Date(data).format("yyyy-MM-dd hh:mm:ss");
				}else{
					return '';
				}
			}
		},{
			colkey : "creat_time",
			name : "订单创建时间",
		}],
		jsonUrl : rootPath + '/client/myorder_findByPage.shtml',
		dymCol:true,
		checkbox : true,
		serNumber : false
	});
	$("#addOrder").click("click", function() {
		addAccount();
	});
	$("#myOrderPlanneradd").click("click", function() {
		myOrderPlanneraddAccount();
	});
	$("#myOrderPlanne").click("click", function() {
		myOrderPlannerAccount();
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
});
function myOrderPlanneraddAccount() {
	var cbox = grid.getSelectedCheckbox();
	
	if (cbox.length > 1 ) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	$.get(rootPath+'/client/order_CheckToPlanner.shtml?id='+cbox,function(data){
		if(eval(data)=="false"){
			layer.msg("选择对象必须为已接收的订单");
			return;
		}else{
			pageii = layer.open({
				title : "添加计划",
				type : 2,
				area : [ "800px", "100%" ],
				content : rootPath + '/client/add_orderplanner.shtml?id=' + cbox
			});
		}
	})
}
function myOrderPlannerAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 ) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "计划明细",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/client/orderplanner_list.shtml?id=' + cbox
	});
}
function addAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 ) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "新增订单",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/client/add_client.shtml?id=' + cbox
	});
}